source("./lib/load_libraries.R")


# EXAMPLES:
# 1:
since <- 2007
to <- 2007

input <- "author:martens author:lennart"
df <- GScholar_Scraper(input, since = since, to=to, citation = 1, journal="")
df.author <- df
head(df.author)

input <- ""

df <- GScholar_Scraper(input, since = since, to=to, citation = 1, journal="BMC+bioinformatics")
df.journal <- df
head(df.journal)

m <- merge(x=df.journal, df.author, by="LINKS", all.x=T)
mypapers <- !is.na(m$CIT.y)

d <- data.frame(m, mypapers)

d <- data.frame(d$LINKS, d$CIT.x, d$TITLES.y, d$mypapers, d$YEAR.x, d$TITLES.x)
colnames(d) <- c("links", "citations", "title", "mypapers", "year", "title")

d[which(d$mypapers == T),]

plot.data[800,]
plot.data <- d
plot.data <- plot.data[order(plot.data$citations,decreasing=T),]
plot.data$links <- factor(plot.data$links, unique(plot.data$links))

text <- c()
for(i in 1:nrow(plot.data)){
          if(plot.data$mypapers[i] == TRUE){
                    text <- c(text, paste(substr(plot.data$title[i], 1, 20), " .. #", plot.data$citations[i]))
          }else{
                    text <- c(text, "")
          }
}

plot.data <- data.frame(plot.data, text)

p <- ggplot(data=plot.data, aes(x=links, y=citations, col=mypapers, size=mypapers, label=text))
p <- p + geom_point()
p <- p + geom_text(size=3, angle=90, hjust=-1)
p <- p + facet_grid(~year)
p <- p + scale_color_manual(values=cbPalette)
p <- p + scale_size_manual(values=c(2,10))
p <- p + opts(axis.ticks = theme_blank(), axis.text.x = theme_blank())
p

